.PHONY: clear, close, container, jupyter, run, shell, test

DIR := ${CURDIR}
IMAGE := jupyter-rust
TAG := 0.1.0
PORT := 9999
FULL_IMAGE := ${IMAGE}:${TAG}
APP_ARGS := -itd --rm --name=${IMAGE} -e JUPYTER_ENABLE_LAB=yes -p ${PORT}:${PORT} -v ${DIR}:/workspace
JUPYTER_ARGS := --no-browser --ip=0.0.0.0 --port=${PORT} --notebook-dir=/workspace --NotebookApp.token=''
RUN_ARGS := -it --rm --name=${IMAGE}-shell -v ${DIR}:/workspace

# clear terminal
clearscr:
	clear && clear

# close jupyterlab container
close:
	docker kill ${IMAGE}

# build jupyterlab container
container:
	docker build -t ${FULL_IMAGE} .

# launch jupyterlab container
jupyter:
	docker run ${APP_ARGS} ${FULL_IMAGE} jupyter lab ${JUPYTER_ARGS}
	echo "Jupyter is running! Open a browser to http://localhost:${PORT}" !

# for debug support: run a container, launching bash
run:
	docker run ${RUN_ARGS} ${FULL_IMAGE} bash

# for debug support: shell into running jupyterlab container
shell:
	docker exec -it ${IMAGE} bash

# for running tests with debug printing.
test: clearscr
	cargo test -- --nocapture